package com.sparrow.common.util;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * 摘要工具类
 * 例如md5
 */
public class DigestUtil {

    public static String toMD5String(String input) {
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            byte[] digest = md.digest(input.getBytes(StandardCharsets.UTF_8));
            return ByteUtil.toHexString(digest);
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("MD5 algorithm not available", e);
        }
    }

    public static void main(String[] args) {
        String str = "i am liushengbao nihao o ";
        System.out.println(toMD5String(str));
    }
}
